<?php

declare(strict_types=1);

use module\user\middleware\NeedLoginMiddleware;
use think\facade\Route;
use app\middleware\{AuthTokenMiddleware, PermissionMiddleware};
use module\user\middleware\AuthTokenMiddleware as UserAuthTokenMiddleware;

Route::group('passport', function () {
    Route::post('login', '\module\user\controller\Passport@login');
    Route::post('register', '\module\user\controller\Passport@register');
    Route::post('logout', '\module\user\controller\Passport@logout')
        ->middleware([UserAuthTokenMiddleware::class]);
    Route::get('verify_token', '\module\user\controller\Passport@verifyToken')
        ->middleware([UserAuthTokenMiddleware::class]);
    Route::post('forget', '\module\user\controller\Passport@forget');
});

Route::group('captcha', function () {
    Route::post('ems', '\module\user\controller\Captcha@ems');
    Route::post('sms', '\module\user\controller\Captcha@sms');
})->middleware([UserAuthTokenMiddleware::class]);

Route::group('profile', function () {
    Route::get('info', '\module\user\controller\Profile@info');
    Route::put('update', '\module\user\controller\Profile@update');
    Route::post('change_mobile', '\module\user\controller\Profile@changeMobile');
    Route::post('change_password', '\module\user\controller\Profile@changePassword');
    Route::post('avatar', '\module\user\controller\Profile@avatar');
    Route::post('bind', '\module\user\controller\Profile@bind');
    Route::post('unbind', '\module\user\controller\Profile@unbind');
})->middleware([UserAuthTokenMiddleware::class, NeedLoginMiddleware::class]);

Route::group('sign_in', function () {
    Route::post('tick', '\module\user\controller\SignIn@tick');
    Route::get('month', '\module\user\controller\SignIn@month');
    Route::get('last', '\module\user\controller\SignIn@last');
})->middleware([UserAuthTokenMiddleware::class, NeedLoginMiddleware::class]);

Route::group('score', function () {
    Route::get('logs', '\module\user\controller\Score@logs');
})->middleware([UserAuthTokenMiddleware::class, NeedLoginMiddleware::class]);

Route::group('invite', function () {
    Route::get('logs', '\module\user\controller\Invite@logs');
})->middleware([UserAuthTokenMiddleware::class, NeedLoginMiddleware::class]);


Route::group('admin', function () {
    Route::get('config$', '\module\user\controller\admin\Config@options');
    Route::post('config$', '\module\user\controller\admin\Config@submit');

    Route::resource('user', '\module\user\controller\admin\User');
    Route::resource('score_log', '\module\user\controller\admin\ScoreLog')->only(['index']);
    Route::resource('vip_log', '\module\user\controller\admin\VipLog')->only(['index']);
})->middleware([
    AuthTokenMiddleware::class,
    PermissionMiddleware::class
]);